public class LogIn {
    private String userName = "admin";
    private String password = "123456";

    //受查情况抛出异常
    //如果不在方法内处理，则必须声明
    public void loginInfo(String userName, String password) throws UserNameErrorException,PassWordErrorException{
        if (!this.userName.equals(userName)) {
            throw new UserNameErrorException("用户名错误!");
        } if (!this.password.equals(password)) {
            throw new PassWordErrorException("密码错误！");
        }
        System.out.println("登陆成功");
    }

    //非受查情况抛出并处理异常
    public void loginInfo2(String userName, String password) {
        try {
            if (!this.userName.equals(userName)) {
                throw new UserNameErrorException("用户名错误!");
            } if (!this.password.equals(password)) {
                throw new PassWordErrorException("密码错误！");
            }
            System.out.println("登陆成功");
        }catch(UserNameErrorException | PassWordErrorException e) {
            e.printStackTrace();
        }
    }

    public void loginInfo1(String userName, String password) {
        if (!this.userName.equals(userName)) {
            System.out.println("用户名错误！");
            return;
        } if (!this.password.equals(password)) {
            System.out.println("密码错误！");
            return;
        }
        System.out.println("登陆成功");
    }

    //如果方法内没有处理，则必须在调用方法的方法中声明或处理
    //若到main方法都只是声明，那么最终会交给 JVM
    public static void main(String[] args) {
        LogIn logIn = new LogIn();
        try{
            logIn.loginInfo("admin", "12345");
        }catch(UserNameErrorException | PassWordErrorException e) {
            e.printStackTrace();
        }
    }

    /*public static void main1(String[] args) {
        LogIn logIn = new LogIn();
        logIn.loginInfo("admin", "12345");
    }*/
}